/**
 * Copyright (C) 2012 The SkyTvOS Project
 * <p/>
 * Version     Date           Author
 * ─────────────────────────────────────
 * 2015年1月6日         Root.Lu
 */

package com.coocaa.x.framework.app;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;

import com.coocaa.x.framework.utils.LogUtils;
import com.umeng.analytics.AnalyticsConfig;

import java.util.Map;

public abstract class CoocaaActivity extends Activity {

    protected Context mContext = null;
    private static Context activityContext = null;


    public static Context getCurrentActivityContext() {
        return activityContext;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = CoocaaApplication.getContext();
        AnalyticsConfig.setAppkey(null, getAppSessionKey());
    }

    @Override
    protected void onResume() {
        activityContext = this;
        super.onResume();
        LogUtils.onPageResume(this, getPageStartParams());
        SplashDialog dialog = getSplashDialog();
        if (dialog != null) {
            dialog.show();
        }
    }

    @Override
    protected void onStart() {
        super.onStart();
        LogUtils.onPageStart(this, getName());
    }

    @Override
    protected void onPause() {
        super.onPause();
        LogUtils.onPagePause(this);
    }

    @Override
    protected void onStop() {
        super.onStop();
        LogUtils.onPageEnd(this, getName());
    }

    public final void post(Runnable r) {
        CoocaaApplication.post(r);
    }

    public final void postDelayed(Runnable r, long delayMillis) {
        CoocaaApplication.post(r);
    }

    @Override
    protected void onSaveInstanceState(Bundle outState) {
        // 禁止super
    }

    public String getName() {
        return getTitle().toString();
    }

    public static int Div(int x) {
        return CoocaaApplication.Div(x);
    }

    public static int Dpi(int x) {
        return CoocaaApplication.Dpi(x);
    }

    protected abstract String getAppSessionKey();

    protected Map<String, String> getPageStartParams() {
        return null;
    }

    protected SplashDialog getSplashDialog() {
        return null;
    }
}
